package com.shundr.user.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shundr.R;
import com.shundr.common.util.DateUtil;
import com.shundr.user.model.RecordInfo;

/**
 * 
 * RecordAdapter 兑换记录适配器
 * 
 * @author larry 2015-7-28 下午5:16:17 
 * @version 1.0.0
 *
 */
public class RecordAdapter extends BaseAdapter{
	public List<RecordInfo> mList;
	private Context mContext;

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int index) {
		return mList.get(index);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	public RecordAdapter(List<RecordInfo> list, Context mContext) {
		super();
		this.mList = list;
		this.mContext = mContext;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		ViewHold viewHold = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_record,null);
			viewHold = new ViewHold();
			viewHold.tvObjType = (TextView) convertView.findViewById(R.id.tv_object_type);
			viewHold.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
			viewHold.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
			convertView.setTag(viewHold);
		}else{
			viewHold = (ViewHold) convertView.getTag();
		}
		try {
			RecordInfo info = mList.get(position);
			// 0:待审核1:充值中2:兑换成功3：兑换失败4：拒绝兑换
			if(info.getAuditStatus() == 2){
				viewHold.tvObjType.setText("兑换成功");
				viewHold.tvObjType.setTextColor(mContext.getResources().getColor(R.color.btn_green_light));
			}else if(info.getAuditStatus() == 4){
				viewHold.tvObjType.setText("兑换失败");
				viewHold.tvObjType.setTextColor(mContext.getResources().getColor(R.color.btn_orange_light));
			}else{
				viewHold.tvObjType.setText("审核中");
				viewHold.tvObjType.setTextColor(mContext.getResources().getColor(R.color.tv_text));
			}
			viewHold.tvTime.setText(DateUtil.getInterval(info.getApplyTime()));
			viewHold.tvTitle.setText(info.getIntegralName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return convertView;
	}

	static class ViewHold{
		TextView tvObjType;
		TextView tvTime;
		TextView tvTitle;
	}
}
